﻿/**********************************************************************
 * Copyright (c) 2008, j. montgomery                                  *
 * All rights reserved.                                               *
 *                                                                    *
 * Redistribution and use in source and binary forms, with or without *
 * modification, are permitted provided that the following conditions *
 * are met:                                                           *
 *                                                                    *
 * + Redistributions of source code must retain the above copyright   *
 *   notice, this list of conditions and the following disclaimer.    *
 *                                                                    *
 * + Redistributions in binary form must reproduce the above copyright*
 *   notice, this list of conditions and the following disclaimer     *
 *   in the documentation and/or other materials provided with the    *
 *   distribution.                                                    *
 *                                                                    *
 * + Neither the name of j. montgomery's employer nor the names of    *
 *   its contributors may be used to endorse or promote products      *
 *   derived from this software without specific prior written        *
 *   permission.                                                      *
 *                                                                    *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  *
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS  *
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE     *
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,*
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES           *
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,*
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)      *
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED*
 * OF THE POSSIBILITY OF SUCH DAMAGE.                                 *
 **********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

using UpdateDnsOMatic.Enums;

namespace UpdateDnsOMatic.Configuration
{
    public class DnsOMaticSection : ConfigurationSection
    {
        internal static readonly string SECTION_NAME = "DnsOMaticSection";

        [ConfigurationProperty("ServerAddress", DefaultValue = "updates.dnsomatic.com")]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 3, MaxLength = 255)]
        public string ServerAddress
        {
            get { return (string)this["ServerAddress"]; }
            set { this["ServerAddress"] = value; }
        }

        [ConfigurationProperty("PublicIpDiscoverServerAddress", DefaultValue = "myip.dnsomatic.com")]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 3, MaxLength = 255)]
        public string PublicIpDiscoverServerAddress
        {
            get { return (string)this["PublicIpDiscoverServerAddress"]; }
            set { this["PublicIpDiscoverServerAddress"] = value; }
        }
        
        // All ASCII letters and numbers accepted. Dots, dashes, and underscores allowed, but not at the beginning or end of the string. 

        // DNS-O-Matic usernames are 3-25 characters. 
        [ConfigurationProperty("UserName", DefaultValue="username")]
        public string UserName
        {
            get { return (string)this["UserName"]; }
            set { this["UserName"] = value; }
        }

        // DNS-O-Matic passwords are 6-20 characters. 
        [ConfigurationProperty("Password", DefaultValue = "password")]
        public string Password
        {
            get { return (string)this["Password"]; }
            set { this["Password"] = value; }
        }

        [ConfigurationProperty("HostNameToUpdate", DefaultValue = "all.dnsomatic.com")]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MinLength = 3, MaxLength = 255)]
        public string HostNameToUpdate
        {
            get { return (string)this["HostNameToUpdate"]; }
            set { this["HostNameToUpdate"] = value; }
        }

        [ConfigurationProperty("Wildcard", DefaultValue="NOCHG")]
        public string Wildcard 
        {
            get { return (string)this["Wildcard"]; }
            set { this["Wildcard"] = value; }
        }
    
        [ConfigurationProperty("MX", DefaultValue="NOCHG")]
        public string MX
        {
            get { return (string)this["MX"]; }
            set { this["MX"] = value; }
        }

        [ConfigurationProperty("BackupMX", DefaultValue = "NOCHG")]
        public string BackupMX
        {
            get { return (string)this["BackupMX"]; }
            set { this["BackupMX"] = value; }
        }

        [ConfigurationProperty("LastKnownIP")]
        public string LastKnownIP
        {
            get { return (string)this["LastKnownIP"]; }
            set { this["LastKnownIP"] = value; }
        }

        [ConfigurationProperty("Interval", DefaultValue = UpdateInterval.Every30Min)]
        public UpdateInterval Interval
        {
            get { return (UpdateInterval)this["Interval"]; }
            set { this["Interval"] = value;  } 
        }
    }
}
